package com.sve.Interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class LoginInterceptor implements HandlerInterceptor {

	 /** 
     * Handlerִ�����֮������������ 
     */  
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}
	 /** 
     * Handlerִ��֮��ModelAndView����֮ǰ����������� 
     */  
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub

	}
	 /** 
     * Handlerִ��֮ǰ����������� 
     */  
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		// TODO Auto-generated method stub
		 String url = request.getRequestURI();
		 System.out.println("zhi��"+url);
	        //URL:login.jsp�ǹ�����;���demo�ǳ���login.jsp�ǿ��Թ������ʵģ�������URL���������ؿ���  
	        if(url.indexOf("user/LoginAction")>=0){  
	            return true;  
	        }  
	        if(url.indexOf("Ticket/Register")>=0){  
	            return true;  
	        } 
	        if(url.indexOf("user/registerAction")>=0){  
	            return true;  
	        } 

	        if(url.indexOf("Ticket/Afters")>=0){  
	            return true;  
	        } 
	        if(url.indexOf("Ticket/BookingInfo")>=0){  
	            return true;  
	        } 
	        if(url.indexOf("Ticket/BookingRoute")>=0){  
	            return true;  
	        } 
	        if(url.indexOf("Ticket/ConductorInfo")>=0){  
	            return true;  
	        }
	        if(url.indexOf("Ticket/UserInfo")>=0){  
	            return true;  
	        }

	        //��ȡSession  
	        HttpSession session = request.getSession();  
	        String username = (String)session.getAttribute("name");  
	        System.out.println("name��"+username);
	        if(username != null){  
	            return true;  
	        }  
	        //�����������ģ���ת����¼����  

	        request.getRequestDispatcher("/Login.jsp").forward(request, response);  

	        //request.getRequestDispatcher("/Station/index").forward(request, response);  

	        return false;  
	}

}
